package com.zzty.common;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import java.io.IOException;
//https://my.oschina.net/CandyDesire/blog/341371
public class Chong {
    public static void main(String[] args) throws IOException {
        HttpClient httpClient=new HttpClient();
        GetMethod getMethod=new GetMethod("https://search.51job.com/list/020000,000000,0000,00,9,99,java,2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare=");
        httpClient.executeMethod(getMethod);
        String html=  getMethod.getResponseBodyAsString();

        html=new String(html.getBytes("iso8859-1"),"gb2312");
        System.out.println(html);
        Document doc=Jsoup.parse(html);
        Elements elements=doc.select("span.t2");
        for(int i=0;i<elements.size();i++){
            Element ele=elements.get(i);
            System.out.println(ele.text());
//            String url=ele.attr("href");
//            GetMethod gm=new GetMethod(url);
//            httpClient.executeMethod(gm);
//            String detailJob=gm.getResponseBodyAsString();
//            detailJob=new String(detailJob.getBytes("iso8859-1"),"gb2312");
//            Document job_doc=Jsoup.parse(detailJob);
//            //职位名称
//            String jobname=job_doc.select("td.sr_bt").get(0).text();
//
//            //公司名称
//            Element company_a=job_doc.select("table.jobs_1 a").get(0);
//            String companyname=company_a.text();
//
//            //职位职能
//            Element target=job_doc.select("strong:contains(职位职能)").get(0);
//            System.out.println(target.nextSibling());
//            TextNode targetNode=(TextNode)target.nextSibling();
//            String targetName=targetNode.text();
//            System.out.println("职位名称: "+jobname);
//            System.out.println("公司名称: "+companyname);
//            System.out.println("职位职能: "+targetName);
//            System.out.println("=====================================");
            //System.out.println(ele.text()+" "+ele.attr("href"));
        }

        getMethod.releaseConnection();

       // getMethod.getResponseBodyAsStream()；
    }
}
